\subsection{Presheaves}
\begin{definition}
    Let \( X \) be a topological space.
    Let \( \operatorname{Open} X \) be the set of open sets on \( X \), and \( \mathbf{AbGp} \) be the class of abelian groups.
    A \emph{presheaf} \( \mathcal F \) on \( X \) of abelian groups is an association
    \[ \operatorname{Open} X \to \mathbf{AbGp} \]
    and for open sets \( U \subseteq V \), a \emph{restriction map}
    \[ \res_U^V : \mathcal F(V) \to \mathcal F(U) \]
    such that
    \[ \res_U^U = \id;\quad \res_U^V \circ \res_V^W = \res_U^W \]
\end{definition}
\begin{example}
    For any topological space \( X \), the presheaf of real-valued continuous functions on \( X \) is defined by
    \[ \mathcal F(U) = \qty{f : U \to \mathbb R \mid f \text{ continuous}} \]
    and
    \[ \res_U^V(f) = \eval{f}_U \]
\end{example}
One can also define presheaves of rings, sets, or other objects by simply replacing the words `abelian groups' in the definition.
\begin{definition}
    A \emph{morphism} \( \varphi \) of presheaves \( \mathcal F, \mathcal G \) on \( X \) is, for each open set \( U \) in \( X \), a homomorphism
    \[ \varphi(U) : \mathcal F(U) \to \mathcal G(U) \]
    such that
    \[\begin{tikzcd}
        {\mathcal F U} & {\mathcal F V} \\
        {\mathcal G U} & {\mathcal G V}
        \arrow["{\res_U^V}", from=1-1, to=1-2]
        \arrow["{\varphi(V)}", from=1-2, to=2-2]
        \arrow["{\varphi(U)}"', from=1-1, to=2-1]
        \arrow["{\res_U^V}"', from=2-1, to=2-2]
    \end{tikzcd}\]
    commutes.
\end{definition}
\begin{remark}
    A presheaf on a topological space \( X \) is just a functor \( (\operatorname{Open} X)^\cop \to \mathbf{AbGp} \), where \( \mathbf{AbGp} \) is the category of abelian groups, and \( \operatorname{Open} X \) is the category where the objects are the open sets in \( X \), and there is a morphism \( U \to V \) if and only if \( U \subseteq V \).
    A morphism of presheaves is just a natural transformation between two such functors.
    Replacing \( \mathbf{AbGp} \) with an arbitrary category \( \mathcal C \), we can define presheaves on \( X \) of objects in \( \mathcal C \).
\end{remark}
\begin{definition}
    A morphism \( \varphi : \mathcal F \to \mathcal G \) of presheaves is \emph{injective} (respectively \emph{surjective}) if \( \varphi(U) : \mathcal F(U) \to \mathcal G(U) \) is injective (respectively surjective) for all open sets \( U \) of \( X \).
\end{definition}

\subsection{Sheaves}
\begin{definition}
    A \emph{sheaf} on \( X \) is a presheaf \( \mathcal F \) on \( X \) such that
    \begin{enumerate}
        \item if \( U \subseteq X \) is open and \( \qty{U_i} \) is an open cover of \( U \), then for \( s \in \mathcal F(U) \), if \( \res_{U_i}^U s = 0 \) for all \( i \), then \( s = 0 \); and
        \item if \( U, \qty{U_i} \) are as in (i), given \( s_i \in \mathcal F(U_i) \) such that \( \res^{U_i}_{U_i \cap U_j} s_i = \res^{U_j}_{U_i \cap U_j} s_j \) for all \( i, j \), then there exists \( s \in \mathcal F(U) \) such that \( \res^U_{U_i} s = s_i \).
    \end{enumerate}
\end{definition}
\begin{remark}
    These two axioms imply that \( \mathcal F(\varnothing) = 0 \).
\end{remark}
A morphism of sheaves is a morphism of the underlying presheaves.
\begin{example}
    \begin{enumerate}
        \item Let \( X \) be a topological space.
        Then the presheaf \( \mathcal F \) given by
        \[ \mathcal F(U) = \qty{f : U \to \mathbb R \mid f \text{ continuous}} \]
        is a sheaf.
        \item Let \( X = \mathbb C \) with the usual Euclidean topology, and let
        \[ \mathcal F(U) = \qty{f : U \to \mathbb C \mid f \text{ bounded and holomorphic}} \]
        Then \( \mathcal F \) is not a sheaf, because the functions \( \id_U \) on bounded open sets \( U \) do not glue together to a bounded holomorphic function on all of \( \mathbb C \).
        This is a failure of locality in our definition of \( \mathcal F \); whether \( f \) is bounded is a global condition.
        \item Let \( G \) be a group and set \( \mathcal F(U) = G \), giving the constant presheaf.
        This is not in general a sheaf.
        For example, if \( U_1, U_2 \) are disjoint, then \( \mathcal F(U_1 \cup U_2) \simeq G \times G \).
        Instead, we can give \( G \) the discrete topology, and define
        \[ \mathcal F(U) = \qty{f : U \to G \mid f \text{ continuous}} = \qty{f : U \to G \mid f \text{ locally constant}} \]
        This is now a sheaf, called the constant sheaf.
        \item Let \( V \) be an irreducible variety over \( k \).
        Let
        \[ \mathcal O_V(U) = \qty{f \in k(V) \mid \forall p \in U,\, f \text{ regular at } p} \]
        where a function \( f \) is regular at \( p \) precisely if it can be represented as a quotient \( \frac{g}{h} \) in a neighbourhood of \( p \) on which \( h \) is nonzero.
        This is called the \emph{structure sheaf} of \( V \); it is a sheaf since regularity is a local condition.
    \end{enumerate}
\end{example}

\subsection{Stalks}
\begin{definition}
    Let \( \mathcal F \) be a presheaf.
    A \emph{section} of \( \mathcal F \) over \( U \) is an element \( s \in \mathcal F(U) \).
\end{definition}
\begin{definition}
    Let \( p \in X \), and \( \mathcal F \) a presheaf on \( X \).
    Then the \emph{stalk} of \( \mathcal F \) at \( p \) is
    \[ \mathcal F_p = \faktor{\qty{(U, s) \mid s \in \mathcal F(U), p \in U}}{\sim} \]
    where
    \[ (U, s) \sim (V, s') \iff \exists W \subseteq U \cap V \text{ open with } p \in W \text{ such that } \res^U_W s = \res^V_W s' \]
    Elements of \( \mathcal F_p \) are called \emph{germs}.
\end{definition}
\begin{example}
    Let \( \mathbb A^1 \) be the affine line, and let \( \mathcal O_{\mathbb A^1} \) be the sheaf of regular functions.
    Its stalk at 0 is
    \[ \mathcal O_{\mathbb A^1, 0} = \qty{\frac{f(t)}{g(t)} \midd g(0) \neq 0} = k[t]_{(t)} \]
\end{example}
\begin{proposition}
    Let \( f : \mathcal F \to \mathcal G \) be a morphism of sheaves on \( X \).
    Suppose that for all \( p \in X \), the induced map \( f_p : \mathcal F_p \to \mathcal G_p \) given by
    \[ f_p((U, s)) = (U, f_U(s)) \]
    is an isomorphism.
    Then \( f \) is an isomorphism.
\end{proposition}
\begin{proof}
    We will show that \( f_U : \mathcal F(U) \to \mathcal G(U) \) are isomorphisms for each \( U \), then define \( f^{-1} \) by \( (f^{-1})_U = (f_U)^{-1} \).

    To show \( f_U \) is injective, consider \( s \in \mathcal F(U) \) with \( f_U(s) = 0 \).
    Since \( f_p \) is injective, \( (U, s) = 0 \) in \( \mathcal F_p \) for every point \( p \in U \).
    Thus for each \( p \in U \), there exists an open neighbourhood \( U_p \subseteq U \) such that \( \res^U_{U_p} s = 0 \).
    The sets \( \qty{U_p \mid p \in U} \) cover \( U \), so as \( \mathcal F \) is a sheaf, \( s = 0 \).

    To show \( f_U \) is surjective, let \( t \in \mathcal G(U) \).
    For each \( p \in U \), there is an element \( (U_p, s_p) \in \mathcal F_p \) such that \( f_p((U_p, s_p)) = (U, t) \in \mathcal G_p \).
    By shrinking \( U_p \) if necessary, we can assume \( f_{U_p}(s_p) = \res^U_{U_p} t \).
    For points \( p, p' \in U \),
    \[ f_{U_p \cap U_{p'}} \qty(\res^{U_p}_{U_p \cap U_{p'}} s - \res^{U_{p'}}_{U_p \cap U_{p'}} s') = \res^U_{U_p \cap U_{p'}} t - \res^U_{U_p \cap U_{p'}} t = 0 \]
    Thus
    \[ \res^{U_p}_{U_p \cap U_{p'}} s - \res^{U_{p'}}_{U_p \cap U_{p'}} s' = 0 \]
    by injectivity of \( f_{U_p \cap U_{p'}} \).
    So there exists a section \( s \) of \( \mathcal F \) over \( U \) such that \( \res^U_{U_p} s = s_p \).
    We now show \( f_U(s) = t \).
    Consider
    \[ \res^U_{U_p} f_U(s) = f_{U_p}\qty(\res^U_{U_p} s) = f_{U_p}(s_p) = \res^U_{U_p} t \]
    Thus \( f_U(s) = t \).
\end{proof}
\begin{remark}
    \begin{enumerate}
        \item Consider the map \( \mathcal F(U) \to \prod_{p \in U} \mathcal F_p \) given by \( s \mapsto ((U, s))_{p \in U} \).
        This is injective by the first sheaf axiom.
        \item Given two morphisms of sheaves \( \varphi, \psi : \mathcal F \rightrightarrows \mathcal G \) with \( \varphi_p = \psi_p \) for all \( p \in X \), we have \( \varphi = \psi \).
    \end{enumerate}
    % proofs as exercises.
\end{remark}

\subsection{Sheafification}
\begin{definition}
    Let \( \mathcal F \) be a presheaf on \( X \).
    Then a morphism \( \mathrm{sh} : \mathcal F \to \mathcal F^{\mathrm{sh}} \) to a sheaf \( \mathcal F^{\mathrm{sh}} \) is a \emph{sheafification} if for any map \( \varphi : \mathcal F \to \mathcal G \) where \( \mathcal G \) is a sheaf, \( \varphi \) factors uniquely through \( \mathrm{sh} \).
    \[\begin{tikzcd}
        {\mathcal F} & {\mathcal F^{\mathrm{sh}}} \\
        & {\mathcal G}
        \arrow["{\mathrm{sh}}", from=1-1, to=1-2]
        \arrow[dashed, from=1-2, to=2-2]
        \arrow["\varphi"', from=1-1, to=2-2]
    \end{tikzcd}\]
\end{definition}
\begin{remark}
    \begin{enumerate}
        \item As this is a definition by a universal property, \( \mathcal F^{\mathrm{sh}} \) along with the map \( \mathrm{sh} : \mathcal F \to \mathcal F^{\mathrm{sh}} \) are unique up to unique isomorphism if they exist.
        \item A morphism of presheaves \( \mathcal F \to \mathcal G \) induces a morphism of sheaves \( \mathcal F^{\mathrm{sh}} \to \mathcal G^{\mathrm{sh}} \).
        \[\begin{tikzcd}
            {\mathcal F} & {\mathcal F^{\mathrm{sh}}} \\
            & {\mathcal G} & {\mathcal G^{\mathrm{sh}}}
            \arrow["{\mathrm{sh}}", from=1-1, to=1-2]
            \arrow[dashed, from=1-2, to=2-2]
            \arrow["\varphi"', from=1-1, to=2-2]
            \arrow["{\mathrm{sh}}"', from=2-2, to=2-3]
        \end{tikzcd}\]
    \end{enumerate}
\end{remark}
\begin{proposition}
    Every presheaf admits a sheafification.
\end{proposition}
\begin{corollary}
    The stalks of \( \mathcal F \) and \( \mathcal F^{\mathrm{sh}} \) coincide.
\end{corollary}
\begin{proof}
    Suppose \( (U, f) \) is a germ of \( \mathcal F^{\mathrm{sh}} \) at \( p \in X \).
    Then \( f(p) \in \mathcal F_p \) is a germ of \( \mathcal F \) at \( p \).
    If \( (U, s) \in \mathcal F_p \), we can produce the germ \( (U, (U, s)_{p \in U}) \) of \( \mathcal F^{\mathrm{sh}} \) at \( p \in X \).
    These are inverse operations, and hence give a bijection of stalks.
\end{proof}
% exercise: find a nonzero presheaf F with F^sh = 0. (ES1 Q10)

\subsection{Kernels and cokernels}
Let \( \varphi : \mathcal F \to \mathcal G \) be a morphism of presheaves.
Then we can define presheaves \( \ker \varphi, \coker \varphi, \im \varphi \) by
\begin{align*}
    (\ker \varphi)(U) &= \ker \varphi_U \\
    (\coker \varphi)(U) &= \coker \varphi_U \\
    (\im \varphi)(U) &= \im \varphi_U
\end{align*}
One can check that these are indeed presheaves.
\begin{proposition}
    The presheaf kernel for a morphism of sheaves is a sheaf.
\end{proposition}
\begin{proof}
    Let \( \varphi : \mathcal F \to \mathcal G \) be a morphism of sheaves, let \( U \subseteq X \) be open, and let \( \qty{U_i}_{i \in I} \) be an open cover of \( U \).
    Let \( f \in (\ker \varphi)(U) \) be such that \( \res^U_{U_i} f = 0 \) for each \( f \).
    Then as \( f \in \mathcal F(U) \), we can use the fact that \( \mathcal F \) is a sheaf to conclude \( f = 0 \).

    Now suppose \( f_i \in (\ker \varphi)(U_i) \) agree on their intersections.
    Then they can be glued as elements of \( \mathcal F(U_i) \) into \( f \in \mathcal F(U) \).
    As \( \varphi_{U_i}(f_i) = 0 \) for each \( i \in I \),
    \[ 0 = \varphi_{U_i}(\res_{U_i}^U f) = \res_{U_i}^U \varphi_U(f) \]
    So as \( \mathcal G \) is a sheaf, \( \varphi_U(f) = 0 \) in \( \mathcal G(U) \).
\end{proof}
However, the presheaf cokernel of a morphism of sheaves is not in general a sheaf.
\begin{example}
    Consider \( X = \mathbb C \) with the Euclidean topology, and let \( \mathcal O_X \) be the sheaf of holomorphic functions on \( X \) under addition.
    Let \( \mathcal O_X^\star \) be the sheaf of nowhere vanishing holomorphic functions under multiplication.
    We have a morphism of sheaves
    \[ \exp : \mathcal O_X \to \mathcal O_X^\star \]
    given by
    \[ f \in \mathcal O_X(U) \mapsto \exp(f) \in \mathcal O_X^\star \]
    The kernel of \( \exp \) is \( 2\pi i \mathbb Z \), where \( \mathbb Z \) is the constant sheaf.
    The cokernel is not a sheaf.
    To show this, consider the cover
    \[ U_1 = \mathbb C \setminus [0, \infty);\quad U_2 = \mathbb C \setminus (-\infty, 0] \]
    and take \( U = U_1 \cup U_2 = \mathbb C \setminus \qty{0} \).
    Let \( f(z) = z \), so \( f \in \mathcal O_X^\star(U) \), but \( f \) is not in the image of \( exp : \mathcal O_X(U) \to \mathcal O_X^\star(U) \) as there is no single-valued logarithm on \( \mathbb C \setminus \qty{0} \).
    Hence \( f \) defines a nonzero section of \( (\coker \exp)(U) \).
    However, restricting to \( U_i \), a single-valued branch of logarithm is defined, so \( f \) is in the image of \( exp : \mathcal O_X(U_i) \to \mathcal O_X^\star(U_i) \).
    Thus \( \res_{U_i}^U f = 1 \), but \( f \neq 1 \), violating the first sheaf axiom.
\end{example}
Similarly, the image presheaf may not be a sheaf.
\begin{definition}
    Let \( \varphi : \mathcal F \to \mathcal G \) be a morphism of sheaves.
    We define the \emph{sheaf cokernel} and the \emph{sheaf image} of \( \varphi \) to be the sheafifications of the presheaf cokernel and presheaf image respectively.
\end{definition}
\begin{remark}
    It turns out that the sequence
    \[\begin{tikzcd}
        0 & {2\pi i \mathbb Z} & {\mathcal O_X} & {\mathcal O_X^\star} & 1
        \arrow[from=1-1, to=1-2]
        \arrow[from=1-2, to=1-3]
        \arrow["\exp", from=1-3, to=1-4]
        \arrow[from=1-4, to=1-5]
    \end{tikzcd}\]
    is an exact sequence of sheaves.
    In particular,
    \[ \ker \exp = 2\pi i \mathbb Z;\quad \coker \exp = 1 \]
\end{remark}
\begin{remark}
    \( \ker \varphi, \coker \varphi \) satisfy the category-theoretic definitions of kernels and cokernels.
    For kernels, the universal property to be satisfied is
    % https://q.uiver.app/#q=WzAsNCxbMSwxLCJcXG1hdGhjYWwgRiJdLFsyLDEsIlxcbWF0aGNhbCBHIl0sWzAsMSwiXFxrZXIgXFx2YXJwaGkiXSxbMSwwLCJcXG1hdGhjYWwgTCJdLFswLDEsIlxcdmFycGhpIl0sWzIsMF0sWzMsMCwiXFxwc2kiXSxbMywxLCIwIl0sWzMsMiwiXFxleGlzdHMhIiwyLHsic3R5bGUiOnsiYm9keSI6eyJuYW1lIjoiZGFzaGVkIn19fV0sWzIsMSwiMCIsMix7ImN1cnZlIjoyfV1d
    \[\begin{tikzcd}
        & {\mathcal L} \\
        {\ker \varphi} & {\mathcal F} & {\mathcal G}
        \arrow["\varphi", from=2-2, to=2-3]
        \arrow[from=2-1, to=2-2]
        \arrow["\psi", from=1-2, to=2-2]
        \arrow["0", from=1-2, to=2-3]
        \arrow["{\exists!}"', dashed, from=1-2, to=2-1]
        \arrow["0"', curve={height=12pt}, from=2-1, to=2-3]
    \end{tikzcd}\]
    For cokernels, we reverse the arrows.
    % https://q.uiver.app/#q=WzAsNCxbMSwxLCJcXG1hdGhjYWwgRiJdLFsyLDEsIlxcbWF0aGNhbCBHIl0sWzAsMSwiXFxjb2tlciBcXHZhcnBoaSJdLFsxLDAsIlxcbWF0aGNhbCBMIl0sWzEsMCwiXFx2YXJwaGkiLDJdLFswLDJdLFswLDMsIlxccHNpIiwyXSxbMSwzLCIwIiwyXSxbMiwzLCJcXGV4aXN0cyEiLDAseyJzdHlsZSI6eyJib2R5Ijp7Im5hbWUiOiJkYXNoZWQifX19XSxbMSwyLCIwIiwwLHsiY3VydmUiOi0yfV1d
    \[\begin{tikzcd}
        & {\mathcal L} \\
        {\coker \varphi} & {\mathcal F} & {\mathcal G}
        \arrow["\varphi"', from=2-3, to=2-2]
        \arrow[from=2-2, to=2-1]
        \arrow["\psi"', from=2-2, to=1-2]
        \arrow["0"', from=2-3, to=1-2]
        \arrow["{\exists!}", dashed, from=2-1, to=1-2]
        \arrow["0", curve={height=-12pt}, from=2-3, to=2-1]
    \end{tikzcd}\]
    % coker is exercise.
\end{remark}
\begin{definition}
    We say that \( \mathcal F \) is a \emph{subsheaf} of \( \mathcal G \), written \( \mathcal F \subseteq \mathcal G \), if there are inclusions \( \mathcal F(U) \subseteq \mathcal G(U) \) compatible with the restriction maps.
\end{definition}
Kernels are examples of subsheaves.

\subsection{Moving between spaces}
Let \( f : X \to Y \) be a continuous map of topological spaces, and let \( \mathcal F \) and \( \mathcal G \) be sheaves on \( X \) and \( Y \) respectively.
\begin{definition}
    The presheaf \emph{pushforward} or \emph{direct image} \( f_\star \mathcal F \) is the presheaf on \( Y \) given by
    \[ f_\star\mathcal F(U) = \mathcal F(f^{-1}(U)) \]
\end{definition}
\begin{proposition}
    The presheaf pushforward of a sheaf is a sheaf.
\end{proposition}
\begin{proof}
    Let \( \qty{U_i}_{i \in I} \) be an open cover of \( U \), and let \( s \in f_\star \mathcal F(U) \) with \( \res^U_{U_i} s = 0 \) for each \( U_i \).
    Then \( \qty{f^{-1}(U_i)}_{i \in I} \) is an open cover of \( f^{-1}(U) \) and satisfies \( \res^{f^{-1}(U)}_{f^{-1}(U_i)} s = 0 \) in \( \mathcal F(f^{-1}(U_i)) \).
    So \( s = 0 \) as \( \mathcal F \) is a sheaf.

    Similarly, if \( s_i \in f_\star \mathcal F(U) \) are compatible sections, then they can be glued into an element of \( \mathcal F(f^{-1}(U)) \).
    But this is precisely an element of \( f_\star \mathcal F(U) \), as required.
\end{proof}
\begin{definition}
    The \emph{inverse image presheaf} \( (f^{-1} \mathcal G)^{\mathrm{pre}} \) is the presheaf on \( X \) given by
    \[ (f^{-1}\mathcal G)^{\mathrm{pre}}(V) = \faktor{\qty{(s_U, U) \mid f(V) \subseteq U, s_U \in \mathcal G(U)}}{\sim} \]
    where \( \sim \) identifies pairs that agree on a smaller open set containing \( f(V) \).
    The \emph{inverse image sheaf} is \( f^{-1} \mathcal G = ((f^{-1} \mathcal G)^{\mathrm{pre}})^{\mathrm{sh}} \).
\end{definition}
% the ~ stuff are all examples of colimits
\begin{example}
    The inverse image presheaf need not be a sheaf, even when \( f \) is an open map.
    Let \( Y \) be a topological space, and let \( X = Y \sqcup Y \).
    Take \( \mathcal G = \underline{\mathbb Z} \) the constant sheaf, and \( \mathcal F = (f^{-1} \mathcal G)^{\mathrm{pre}} \).
    Let \( U \subseteq Y \) be open, and let \( V = f^{-1}(U) \).
    Then \( \mathcal F(V) = \mathcal G(U) = \mathbb Z \), assuming \( U \) is connected.
    But \( V = U \sqcup U \), so \( \mathcal F^{\mathrm{sh}}(V) = \mathcal G(U) \times \mathcal G(U) = \mathbb Z^2 \).
\end{example}
\begin{example}
    Let \( \mathcal F \) be a sheaf on \( X \), and let \( \pi \) be the map from \( X \) to a point.
    Then \( f_\star \mathcal F \) is a sheaf on a point, which is just an abelian group, specifically \( \mathcal F(\pi^{-1}(\qty{\bullet})) = \mathcal F(X) \).
\end{example}
We will use the notation
\[ \mathcal F(X) = \Gamma(X, \mathcal F) = H^0(X, \mathcal F) \]
where \( \Gamma \) is called the \emph{global sections}, and \( H_0 \) is called the \emph{0th cohomology} with coefficients in \( \mathcal F \).

For \( p \in X \), \( i : \qty{p} \to X \).
Let \( \mathcal G \) be a sheaf on \( \qty{p} \), which is an abelian group \( A \).
Consider the sheaf \( i_\star \mathcal G \) on \( X \), defined by
\[ (i_\star \mathcal G)(U) = \begin{cases}
    0 & \text{if } p \notin U \\
    A & \text{if } p \in U
\end{cases} \]
This is called the \emph{skyscraper} at \( p \) with value \( A \).
